program main

    use dnadmod
    implicit none
    type(dual) :: x, y
    real :: a, b, c
    a = 2.0
    b = 1.0
    c = 0.0
    
    print *, "demo1: y = (a + b*b)*exp(c)"
    
    x = dual(a, [1.0])
    y = (x + b*b)*exp(c)
    write (*, *) "[y, dy/da] = ", y
    
    x = dual(b, [1.0])
    y = (a + x*x)*exp(c)
    write (*, *) "[y, dy/db] = ", y
    
    x = dual(c, [1.0])
    y = (a + b*b)*exp(x)
    write (*, *) "[y, dy/dc] = ", y
    
    ! - - -
    
    print *, ""
    print *, "demo2: y = (a + b)*(b + 1.0)"
    
    x = dual(a, [1.0])
    y = (x + b)*(b + 1.0)
    write (*, *) "[y, dy/da] = ", y
    
    x = dual(b, [1.0])
    y = (a + x)*(x + 1.0)
    write (*, *) "[y, dy/db] = ", y
    
end program main

!> demo1: y = (a + b*b)*exp(c)
!> [y, dy/da] =    3.000000       1.000000
!> [y, dy/db] =    3.000000       2.000000
!> [y, dy/dc] =    3.000000       3.000000
!>
!> demo2: y = (a + b)*(b + 1.0)
!> [y, dy/da] =    6.000000       2.000000
!> [y, dy/db] =    6.000000       5.000000